package org.springframework.samples.mvc.basic.sample;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.samples.mvc.basic.account.Account;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value="/sample")
public class SampleController
{
    @InitBinder
    public void initBinder(WebDataBinder binder)
    {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(format, false));
    }

	@RequestMapping(method=RequestMethod.GET)
	public String getCreateForm(Model model) {
		model.addAttribute(new Account());
        return "/sample/view";
	}

    @RequestMapping("/{date}")
    public String doSample(@PathVariable Date date, Model model)
    {
        System.out.println(date);
        // do something...
        return "/sample/view";

    }
}
